home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / xulrunner / python / clipboard.py < prev    next >
Encoding:
Python Source  |  2007-11-12  |  1.5 KB  |  44 lines

  1. # Miro - an RSS based video player application
  2. # Copyright (C) 2005-2007 Participatory Culture Foundation
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  17.  
  18. """clipboard.py.  Used to access the clipboard from python."""
  19.  
  20. from templatehelper import toUni
  21. from ctypes import windll, c_char_p
  22. CF_TEXT = 1
  23.  
  24. OpenClipboard = windll.user32.OpenClipboard
  25. GetClipboardData = windll.user32.GetClipboardData
  26. CloseClipboard = windll.user32.CloseClipboard
  27. GlobalLock = windll.kernel32.GlobalLock
  28. GlobalUnlock = windll.kernel32.GlobalUnlock
  29.  
  30. def getText():
  31.      text = None
  32.      if OpenClipboard(None):
  33.          try:
  34.              hClipMem = GetClipboardData(CF_TEXT)
  35.              if hClipMem:
  36.                  GlobalLock.restype = c_char_p
  37.                  text = GlobalLock(hClipMem)
  38.                  GlobalUnlock(hClipMem)
  39.          finally:
  40.              CloseClipboard()
  41.      if text is not None:
  42.          text = toUni(text)
  43.      return text
  44.